package com.sense.kukoo.biz_explore.model

import com.sense.kukoo.biz_explore.net.ExploreHttpApi
import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.bean.*
import com.sense.kukoo.common.repo.http.KukooHttpApi
import com.sense.kukoo.common.repo.http.KukooHttpManager
import com.sense.kukoo.common.repo.http.bean.IndexContentBean
import com.sense.kukoo.common.repo.http.bean.UserSearchBean
import okhttp3.RequestBody
import retrofit2.http.Path

class SearchModel:BaseMvvmModel() {

    private val TAG: String = javaClass.simpleName
    override fun onModelCleared() {}

    suspend fun searchQueryPage(pageIndex: Int, pageSize: Int): ResultBean<QueryPageBean<SearchRecordBean>> {
        return KukooHttpManager.instance
            .createHttpClient(ExploreHttpApi::class.java)
            .searchQueryPage(""+pageIndex, ""+pageSize)
    }

    suspend fun hotWordQueryPage(): ResultBean<QueryPageBean<HotWordBean>> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("pageIndex", 1)
        hashMap.put("pageSize", 10)
        hashMap.put("query", HashMap<String, Any>())
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(ExploreHttpApi::class.java)
            .hotWordQueryPage(mRequestBody)
    }

    suspend fun searchBook(keywords:String, pageIndex: Int, pageSize: Int): ResultBean<QueryPageBean<BookBean>> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("keywords", keywords)
        hashMap.put("pageIndex", pageIndex)
        hashMap.put("pageSize", pageSize)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)
        //
        return KukooHttpManager.instance
            .createHttpClient(ExploreHttpApi::class.java)
            .searchBook(mRequestBody)
    }

    suspend fun hotWordList(): ResultBean<List<String>> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .hotWordList()
    }

    suspend fun userSearch(
        pageIndex: Int,
        pageSize: Int,
        keyword: String,
    ): ResultBean<List<UserSearchBean>> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .userSearchByKeyword("${pageIndex}", "${pageSize}", keyword)
    }

    suspend fun keywordSearch(
        pageIndex: Int,
        pageSize: Int,
        keyword: String,
    ): ResultBean<List<IndexContentBean>> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .keywordSearch("${pageIndex}", "${pageSize}", keyword)
    }

    suspend fun subscription(
        userId: Long
    ): ResultBean<Boolean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .subscription("${userId}")
    }

}